home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-02 | 2.2 KB | 71 lines | [TEXT/GEOL] |
- Item 5138121 1-March-90 06:16PST
-
- From: NAUTIL France - Dev, Nautil Info Lyon,IDV
-
- To: CPLUS.APPLE$ C++ Interest List--Apple Employees
- CPLUS.DEV$ C++ Interest List--Developers
-
- Sub: "pure base" notion
-
- How can I define a "pure base" class wich is never directly instancied?
-
- My code is stand-alone and must be independant of "CPlusLib.o", so I define
- some base classes with operators new and delete :
-
- class TSomeSpecialAlloc {
- public:
- void* operator new(size_t size) { return NewPtr(size); }
- void operator delete(void* p) { DisposPtr((Ptr)p); }
- };
-
- class TAnotherSpecialAlloc {
- public:
- void* operator new(size_t) { return NewPtr(size); }
- void operator delete(void*) { DisposPtr((Ptr)p); }
- };
-
- Here is the "pure base" class (never directly instancied) :
-
- class TPureBase {
- public:
- TPureBase(int) {}
- };
-
- Now, I want to declare the following classes :
-
- class A : public TSomeSpecialAlloc, public TPureBase {
- public:
- A(int i) : TPureBase(i) {}
- };
-
- class B : public TAnotherSpecialAlloc, public TPureBase {
- public:
- B(int i) : TPureBase(i) {}
- };
-
- The problem is that CFront (1.0B1 for MPW C++ 3.1B1) generates an allocation
- function for TPureBase in the A and B constructors. And this allocation
- involves default function in "CPlusLib.o" (arrgl!). It seems that CFront uses
- the following algorithm:
-
- 1- In a constructor, generate checking for allocation.
- 2- In a derivated constructor, generate full constructor for the base.
-
- I think that (at least for inline constructors!) it is not very difficult to
- generate correct instructions avoiding a multiple allocation checking for a
- multiple base classes!!! (Well, this is a poor beta version of CFront, so final
- release will be perfect... Isn't it?!!!).
-
- Now, I have tried to bypass this feature declaring empty new and delete
- operators for class TPureBase, then declaring A and B "public TxSpecialAlloc,
- private TPureBase". I was thinking that, in this case, TPureBase operators was
- hidden for A and B. But CFront is really a facetious compiler and he said:
- "error: ambiguous operator ::new"! (arrgl again!).
-
- Help !
- Etienne Vautherin
-
-
-
-
-